var QQMapWX = require('../../utils/qqmap-wx-jssdk/qqmap-wx-jssdk');
var qqmapsdk;
Page({
  data: {
    city: '', // 定位
    myAddress: '', // 我的地址
    cinemaList: [], // 影院
    distance: '', // 影院 - 距离
  },

  onLoad: function (options) {
    var _this = this;
    // 底部导航 - 切换
    this.getTabBar().setData({
        current: 3
      }),
      // 实例化API核心类
      qqmapsdk = new QQMapWX({
        key: 'PZXBZ-2DN63-KY73I-3O3RU-ADX4O-ZRF7R'
      });
    // 获取位置
    wx.getLocation({
      success(res) {
        // 逆地址解析
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          coord_type: 1,
          success(res1) {
            // console.log(res1)
            _this.setData({
              city: res1.result.address_component.city,
              myAddress: res1.result.address
            })
          }
        });
        // 地点搜索
        qqmapsdk.search({
          keyword: '影院',
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success(res2) {
            var items = res2.data.map(ele => ele._distance)
            var item = items.map(ele => {
              return Math.floor(ele / 1000) + '.' + Math.floor(ele / 100) % 10
            })
            _this.setData({
              cinemaList: res2.data,
              distance: item
            })
          }
        })
      }
    })
  }
})